#include <vector>
using namespace std;
vector<int> productExceptSelf(vector<int> &nums) {
  int n = nums.size();
  vector<int> pre_product(n, 0);
  vector<int> suf_product(n, 0);
  int i = 1, j = n - 2;
  pre_product[0] = nums[0];
  suf_product[n - 1] = nums[n - 1];
  while (i < n) {
    pre_product[i] = nums[i] * pre_product[i - 1];
    suf_product[j] = nums[j] * suf_product[j + 1];
    i++;
    j--;
  }
  vector<int> res(n, 0);
  res[0] = suf_product[1];
  res[n - 1] = pre_product[n - 2];
  for (int i = 1; i < n - 1; i++) {
    res[i] = pre_product[i - 1] * suf_product[i + 1];
  }
  return res;
}

int main() {
  vector<int> nums{1, 2, 3, 4};
  auto res = productExceptSelf(nums);
  return 0;
}